//
//  XYDialogView.m
//  JinXiaoChao
//
//  Created by 找汽配 on 2018/1/23.
//

#import "XYDialogView.h"

@interface XYDialogView ()

@property (weak, nonatomic) IBOutlet UIView * backgroundView;

@end

@implementation XYDialogView

+ (instancetype)dialogView {
    return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] firstObject];
}

- (void)show {
    self.hidden = NO;
    [UIView animateWithDuration:0.25 animations:^{
        self.backgroundView.alpha = 1;
    }];
    [self.contentView show];
}

- (void)hide {
    [UIView animateWithDuration:0.25 animations:^{
        self.backgroundView.alpha = 0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
        if (self.delegate && [self.delegate respondsToSelector:@selector(dialogViewDidHide:)]) {
            [self.delegate dialogViewDidHide:self];
        }
    }];
    [self.contentView hide];
}

- (void)setContentView:(XYDialogViewContentView *)contentView {
    if (_contentView) {
        [_contentView removeFromSuperview];
        _contentView = nil;
    }
    [self addSubview:contentView];
    _contentView = contentView;
}

- (IBAction)cancelButtonTouchUpInside {
    [self hide];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
